set (READLINE_HINTS "/usr/local/opt/readline/lib")
if (USE_STATIC_LIBRARIES)
	find_library (READLINE_LIB NAMES libreadline.a HINTS ${READLINE_HINTS})
else ()
	find_library (READLINE_LIB NAMES readline HINTS ${READLINE_HINTS})
endif ()
if (USE_STATIC_LIBRARIES)
	find_library (EDIT_LIB NAMES libedit.a)
else ()
	find_library (EDIT_LIB NAMES edit)
endif ()
if (USE_STATIC_LIBRARIES)
	find_library (CURSES_LIB NAMES libcurses.a)
else ()
	find_library (CURSES_LIB NAMES curses)
endif ()
if (USE_STATIC_LIBRARIES)
	find_library (TERMCAP_LIB NAMES libtermcap.a termcap)
else ()
	find_library (TERMCAP_LIB NAMES termcap)
endif ()

if (READLINE_LIB)
	include_directories ("/usr/local/opt/readline/include")
	add_definitions (-D USE_READLINE)
	set (LINE_EDITING_LIBS ${READLINE_LIB} ${TERMCAP_LIB})
	message (STATUS "Using line editing libraries: ${LINE_EDITING_LIBS}")
elseif (EDIT_LIB)
	add_definitions (-D USE_LIBEDIT)
	set (LINE_EDITING_LIBS ${EDIT_LIB} ${CURSES_LIB} ${TERMCAP_LIB})
	message (STATUS "Using line editing libraries: ${LINE_EDITING_LIBS}")
else ()
	message (STATUS "Not using any library for line editing.")
endif ()

add_library (clickhouse-client Client.cpp)
target_link_libraries (clickhouse-client dbms ${LINE_EDITING_LIBS} ${Boost_PROGRAM_OPTIONS_LIBRARY})
install (FILES config.xml DESTINATION /etc/clickhouse-client COMPONENT clickhouse-client)

add_library (clickhouse-benchmark Benchmark.cpp)
target_link_libraries (clickhouse-benchmark dbms ${Boost_PROGRAM_OPTIONS_LIBRARY})

if (ENABLE_TESTS)
	add_subdirectory (tests)
endif (ENABLE_TESTS)
